<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<ad unit-id="adunit-512347906ad14957"></ad>
		<!-- #endif -->
		<view style="text-align: center;">
			<image src="../../static/hei.jpg"></image>
			<button type="primary" @click="toIndex" class="buttonC" style="-webkit-flex: 1;flex: 1; margin: 10px;">我也要玩</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				audio_list: getApp().globalData.audio_list,
				id: 0
			}
		},
		onLoad(options) {
			var self = this
			// 为了防止苹果手机静音无法播放
			uni.setInnerAudioOption({
				obeyMuteSwitch: false
			})
			console.log('options')
			console.log(options)
			if (typeof(options.id) != 'undefined') {
				console.log('准备播放')
				this.id = options.id
				this.playing(self.audio_list[options.id].audio_src)
			}
		},
		onShareAppMessage(res) {
			console.log('分享')
			console.log(res)
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			
			return {
				title: '送你一份神秘礼物吧！',
				path: '/pages/index/from_share?id=' + this.id,
				imageUrl: '../../static/gift.jpg'
			}
		},
		onShareTimeline(res) {
			console.log('分享')
			console.log(res)
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '惊喜礼物:送你一份神秘礼物吧！',
				path: '/pages/index/from_share?id=' + this.id,
				imageUrl: '../../static/gift.jpg'
			}
		},
		methods: {
			toIndex() {
				uni.navigateTo({
					url: "/pages/index/index",
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					}
				});
			},
			playing(src) {
				const innerAudioContext = uni.createInnerAudioContext();
				innerAudioContext.autoplay = true;
				innerAudioContext.src = src;
				innerAudioContext.onPlay(() => {
					console.log('开始播放');
				});
				innerAudioContext.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
				});
			},
		}
	}
</script>

<style>

</style>
